<?php

namespace App\Http\Middleware;

use Closure;
use App\Traits\RetrunService;
use App\AdminModels\Admin;
use App\Services\Admin\AdminUser;

class AdminSessionMiddleware
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if(empty($request->session()->get('session_id')))return redirect('/login');

        $where[] = ['id',$request->session()->get('session_id')];
        $admin = AdminUser::info($where);
        if(empty($admin))return redirect('/login');

        $user['session_id'] = $request->session()->get('session_id');
        $user['session_role_name'] = '超级管理员';
        View()->share('user',$user);

        return $next($request);
    }
}
